namespace G1.EngineV
{

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Util;
    using Android.Views;
    using Android.Widget;
    using Android.Graphics;
    using Android.Graphics.Drawables;


    public sealed class View : Android.Views.SurfaceView, ISurfaceHolderCallback
    {

        private Thread _Thread;

        public View( Context context, IAttributeSet attrs ) : base( context, attrs )
        {
            Initialize();
        }

        public View( Context context, IAttributeSet attrs, int defStyle )
            : base( context, attrs, defStyle )
        {
            Initialize();
        }

        private void Initialize()
        {
            this.Holder.AddCallback( this );
            this.Focusable = true;
            this._Thread = new Thread( this.Holder, this );
        }

        public override bool OnTouchEvent( MotionEvent e )
        {
            return base.OnTouchEvent( e );
        }

        public void SurfaceChanged( ISurfaceHolder holder, int format, int width, int height )
        {
        }

        public void SurfaceCreated( ISurfaceHolder holder )
        {
            this._Thread.Start();
            
        }

        public void SurfaceDestroyed( ISurfaceHolder holder )
        {
            this._Thread.Running = false;
            this._Thread.Join();
        }
    }
}
